<template>
  <div>
    <Myheader title="购物车 - Happy" bg="red" color="#fff"></Myheader>
    <div class="main">
      <MyGoods v-for="val in list" :key="val.id" :obj="val"></MyGoods>
      <Myfooter @change="status" :arr="list" :total="total"></Myfooter>
    </div>
  </div>
</template>

<script>
import Myheader from "./components/MyHeader";
import Myfooter from "./components/MyFooter";
import MyGoods from "./components/MyGoods";
export default {
  components: {
    Myheader,
    Myfooter,
    MyGoods,
  },
  data() {
    return {
      list: [],
    };
  },
  created() {
    this.$axios({
      url: "https://www.escook.cn/api/cart",
    }).then((res) => {
      this.list = res.data.list;
      console.log(res);
    });
  },
  methods: {
    status(val) {
      this.list.forEach((obj) => {
        obj.goods_state = val;
      });
    },
  },
  computed: {
    total() {
      return this.list.reduce((sum, p) => {
        return sum + p.goods_count * p.goods_price;
      }, 0);
    },
  },
};
</script>

<style scoped>
.main {
  padding: 45px 0 50px 0;
}
</style>